﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LIMS.Entities;
using LIMS.DataAccess;
using System.Collections;
using System.Reflection;
using Castle.Core.Logging;
using NHibernate.Criterion;

namespace LIMS.Service
{
    public class ProductManagementService : IProductManagementService
    {
        //Private DBA interfaces
        private IDaoFactory oDBFactory;
        private IProductDAO oProductDBA;
        private ILogger logger;

        //Constructor
        public ProductManagementService(IDaoFactory oDBOp, ILogger oLogger)
        {
            this.oDBFactory = oDBOp;
            this.oProductDBA = oDBFactory.GetProductDAO();
            this.logger = oLogger;
        }
        #region IProductManagementService Members
       
        /// <summary>
        /// Save
        /// </summary>
        /// <param name="newProduct"></param>
        /// <returns></returns>
        public bool Save(Product newProduct)
        {
            return oProductDBA.QuickSaveOrUpdate(ref newProduct);
        }
        /// <summary>
        /// Delete
        /// </summary>
        /// <param name="dProduct"></param>
        /// <returns></returns>
        public bool Delete(Product dProduct)
        {
            return oProductDBA.QuickDelete(dProduct);
        }

        /// <summary>
        /// GetAllProductsForGrid
        /// </summary>
        /// <param name="oGrdData"></param>
        /// <returns></returns>

        public List<Product> GetAllProducts()
        {
            List<Product> oAllProducts = new List<Product>();
            try
            {
                //return oCountiesDBA.GetAll();
                ICriterion oCriteriaStatus = Expression.Eq("Status", Resource.ACTIVE_STATUS);
                return oProductDBA.GetByCriteria(oCriteriaStatus);
            }
            catch (Exception ex)
            {
                logger.Error("Error in Getting Products ", ex);
            }
            return oAllProducts;
        }

        /// <summary>
        /// GetAllProductsForGrid
        /// </summary>
        /// <param name="oGrdData"></param>
        /// <returns></returns>
        public List<Product> GetAllProductsForGrid(ref GridViewData oGrdData)
        {
            return oProductDBA.GetAllForGridView(ref oGrdData);
        }


        #endregion
    }
}
